/** FASSIT (Forms of Selective Attention in Intelligent Transportation Systems)
 * Computational Creativity and Digital Media
 * Cognitive and Media Systems Group
 * Centre for Informatics and Systems of the University of Coimbra (CISUC)
 *
 * Copyright (c) 2010-2013 University of Coimbra, Portugal
 * All rights reserved.
 */
package poi.SurpriseCalculator;

import poi.Info.DaysOff;
import poi.Info.POI;
import poi.Info.Price;
import poi.Surprise.SurpriseDaysOff;

import java.util.ArrayList;
import java.util.HashMap;

import masterAgent.DBmanager.DBConnection;
import masterAgent.DBmanager.DBManager;

import agent.Context.Goal;

import functionsVariables.Constants;

/**
 * This class is used to calculate the Master agent Surprise for the parameter
 * DayOff
 * 
 * @author Hernani Costa
 * @version 0.1 date: 28/11/2012
 */
public class SurpriseCalculatorForDaysOff {
	HashMap<Integer, SurpriseDaysOff> poiSurpriseDayOff;

	/**
	 * ------------------------------------------------------------------------
	 * Constructor class
	 * ------------------------------------------------------------------------
	 * 
	 * @param pois - list with the POIs that we intend to calculate the surprise
	 */
	public SurpriseCalculatorForDaysOff(HashMap<Integer,POI> pois) {
		poiSurpriseDayOff = new HashMap<Integer, SurpriseDaysOff>();
		calculates_Surprise_Knowledge_About_DayOff(pois);
	}

	/**
	 * Calculates the Surprise for the parameter DayOff
	 * 
	 * @param pois
	 *            - list with the POIs that we intend to calculate the surprise
	 */
	private void calculates_Surprise_Knowledge_About_DayOff(HashMap<Integer,POI> pois) {
		SurpriseDaysOff surpriseDayOff = null;
		double val = 0.0;
		for (POI poi : pois.values()) {

			DaysOff dayOff = poi.getDaysOff();
			if (!dayOff.hasDaysOff()) {
				val = 1.0 / 7.0;
				surpriseDayOff = new SurpriseDaysOff(val, val, val, val, val,
						val, val);
			} else {
				ArrayList<String> listOfDaysOff = dayOff.getListDaysOff();
				double divisor = listOfDaysOff.size();
				int[] intDayOff = Constants.getIntFromStrDays(listOfDaysOff);

				surpriseDayOff = new SurpriseDaysOff(intDayOff[0]
						* (1.0 / divisor), intDayOff[1] * (1.0 / divisor),
						intDayOff[2] * (1.0 / divisor), intDayOff[3]
								* (1.0 / divisor), intDayOff[4]
								* (1.0 / divisor), intDayOff[5]
								* (1.0 / divisor), intDayOff[6]
								* (1.0 / divisor));
			}

			poiSurpriseDayOff.put(poi.getPoiID(), surpriseDayOff);
		}
	}

	// ------------------------------------------------------------------------
	// ------------------------GETs and SETs-----------------------------------
	// ------------------------------------------------------------------------

	public HashMap<Integer, SurpriseDaysOff> getPoiSurpriseDayOff() {
		return poiSurpriseDayOff;
	}

	/**
	 * 
	 * @return a String with the Surprise values for the parameter Schedule, for all POIs
	 */
	public String to_String(){
		String info="";
		for(int poiID: poiSurpriseDayOff.keySet()){
			info += "poiID: "+ poiID +"\n\t"+poiSurpriseDayOff.get(poiID).to_String()+"\n";
		}
		return info;
	}
	
	
	/**
	 * ------------------------------------------------------------------------
	 * Only for debug purpose
	 * ------------------------------------------------------------------------
	 */
//	public static void main(String args[]) {
//		//DBManager manager = new DBManager();
//		DBConnection connector = new DBConnection();
//		
//		POI poi = connector.getPOI(1507669);
//		System.err.println("O pesquisado\n" + poi.to_String() + "\n\n");
//
//		ArrayList<POI> pois = connector.getPOIsNearLocation(poi.getLocation(), 200,
//				new Goal().getDinner());
////		for (POI p : pois) {
////			System.err.println(p.to_String());
////		}
//		
//		MAKnowledgeAboutDaysOff m = new MAKnowledgeAboutDaysOff(pois);
//		System.out.println(m.to_String());
//	}

}
